function analyze_pathways_both_dirrections()
    tStart = tic;
    tElapsed = 0;
    
    model = evalin('base', 'model');
    listOfPathways = evalin('base', 'listOfPathways'); 
    prod_listOfPathways = evalin('base', 'prod_listOfPathways'); 
    defines = evalin('base', 'defines');
   
    arrayOfAllPathwaysWeights = [];
    analyzedPathways = [];
    assignin('base', 'arrayOfAllPathwaysWeights', arrayOfAllPathwaysWeights);
    assignin('base', 'analyzedPathways', analyzedPathways);
    
    if isempty(listOfPathways)
        message = 'Returning back - na data to fill!'
        return;
    end
    
    message = 'Launching Cobra! ....'
    initCobraToolbox;

    sortOrder = splitStringToCells(defines.analysisSortArray);
    analysisCoeficients = splitStringToCells(defines.analysisCoeficients);
  
    bar = waitbar(0,'Please wait... Looking for all pathways');
   
    for i = 1: length(listOfPathways)
        waitbar(i/length(listOfPathways), bar, [num2str(i), ' Pathways of ', num2str(length(listOfPathways)), ' total' ])
        drawnow
        disp(['##### PATHWAY: ' num2str(i)]);
        currentPathway = listOfPathways{i};
         
         
        [pathwayStatstics, listOfPoolMetabolitesInPathway,zeroSolutionFBA, ...
                listOfPathwaysWhereReactionsArePresented, arrayOfWeightsOfPathway, returnModel]= ...
                    get_pathway_statistics(currentPathway, model,  true, false);
         
         if ~zeroSolutionFBA
             
              
             barP = waitbar(0,'Please wait... Looking for product pathways');       
             for ip = 1: length(prod_listOfPathways)
                waitbar(ip/length(prod_listOfPathways), barP, [num2str(ip), ' Pathways of ', num2str(length(prod_listOfPathways)), ' total' ])
                drawnow  

                currentPathwayProd = prod_listOfPathways{ip};
                
                [prod_pathwayStatstics, prod_listOfPoolMetabolitesInPathway,...
                prod_zeroSolutionFBA, prod_listOfPathwaysWhereReactionsArePresented, ...
                prod_weights, prod_returnModel] = ...
                    get_pathway_statistics(currentPathwayProd, returnModel,  false, true, arrayOfWeightsOfPathway(2));

                if ~prod_zeroSolutionFBA
                     
                    index = 0;
                    index_sub = 0;
                   
                    if defines.analysisOption == '1'
                        resultArr = [0 0 0 0 0 0 0 0 i ip];
                        resultArr(abs(str2num(sortOrder{1}))) = prod_weights(2);
                        resultArr(abs(str2num(sortOrder{2}))) = prod_weights(4);
                        resultArr(abs(str2num(sortOrder{3}))) = prod_weights(3);
                        resultArr(abs(str2num(sortOrder{4}))) = prod_weights(1);
                        resultArr(abs(str2num(sortOrder{5}))) = arrayOfWeightsOfPathway(1);
                        resultArr(abs(str2num(sortOrder{6}))) = prod_weights(5) + arrayOfWeightsOfPathway(5);
                        resultArr(abs(str2num(sortOrder{7}))) = prod_weights(6) + arrayOfWeightsOfPathway(6);

                        sorting = [1 2 3 4 5 6 7];
                        for is = 1: length(sorting)
                            if str2num(sortOrder{is}) < 0
                                sorting(is) = sorting(is) * -1;
                            end
                        end
                        
                        %todo return only to analysis
                        arrayOfAllPathwaysWeights = [arrayOfAllPathwaysWeights; resultArr];
                    else
                        resultArr = [0 0 0 0 0 0 0 0 i ip];
                        resultArr(1) = prod_weights(2);
                        resultArr(2) = prod_weights(4);
                        resultArr(3) = prod_weights(3);
                        resultArr(4) = prod_weights(1);
                        resultArr(5) = arrayOfWeightsOfPathway(1);
                        resultArr(6) = prod_weights(5) + arrayOfWeightsOfPathway(5);
                        resultArr(7) = prod_weights(6) + arrayOfWeightsOfPathway(6);

                        arrayOfAllPathwaysWeights = [arrayOfAllPathwaysWeights; resultArr];
                        for iw = 1 : length(arrayOfAllPathwaysWeights(:,1))
                            firstParam = calculate_integral_weight(arrayOfAllPathwaysWeights(iw,1), ... 
                            min(arrayOfAllPathwaysWeights(:,1)), ...
                            max(arrayOfAllPathwaysWeights(:,1)), ...
                            str2num(analysisCoeficients{1}), false)

                            secondParam = calculate_integral_weight(arrayOfAllPathwaysWeights(iw,2), ... 
                            min(arrayOfAllPathwaysWeights(:,2)), ...
                            max(arrayOfAllPathwaysWeights(:,2)), ...
                            str2num(analysisCoeficients{2}), false)

                            thirdParam = calculate_integral_weight(arrayOfAllPathwaysWeights(iw,3), ... 
                            min(arrayOfAllPathwaysWeights(:,3)), ...
                            max(arrayOfAllPathwaysWeights(:,3)), ...
                            str2num(analysisCoeficients{3}), false)

                            fourthParam = calculate_integral_weight(arrayOfAllPathwaysWeights(iw,4), ... 
                            min(arrayOfAllPathwaysWeights(:,4)), ...
                            max(arrayOfAllPathwaysWeights(:,4)), ...
                            str2num(analysisCoeficients{4}), true)

                            fiftParam = calculate_integral_weight(arrayOfAllPathwaysWeights(iw,5), ... 
                            min(arrayOfAllPathwaysWeights(:,5)), ...
                            max(arrayOfAllPathwaysWeights(:,5)), ...
                            str2num(analysisCoeficients{5}), true)

                            sixtParam = calculate_integral_weight(arrayOfAllPathwaysWeights(iw,6), ... 
                            min(arrayOfAllPathwaysWeights(:,6)), ...
                            max(arrayOfAllPathwaysWeights(:,6)), ...
                            str2num(analysisCoeficients{6}), true)

                            seventhParam = calculate_integral_weight(arrayOfAllPathwaysWeights(iw,7), ... 
                            min(arrayOfAllPathwaysWeights(:,7)), ...
                            max(arrayOfAllPathwaysWeights(:,7)), ...
                            str2num(analysisCoeficients{7}), true)

                            weight = firstParam + secondParam + thirdParam + fourthParam + fiftParam + sixtParam + seventhParam;

                            arrayOfAllPathwaysWeights(iw,8) = weight;
                        end

                        sorting = [-8];
                    end
                    
                    [arrayOfAllPathwaysWeights, e] = sortrows(arrayOfAllPathwaysWeights, sorting);

                    arrTemporary = arrayOfAllPathwaysWeights(length(arrayOfAllPathwaysWeights(:,1)),:);

                    if length(arrayOfAllPathwaysWeights(:,1)) > str2num(defines.numberOfBestPathwaysReturned) 
                       index = arrTemporary(9);%subs
                       index_sub = arrTemporary(10); %prod
                       arrayOfAllPathwaysWeights(length(arrayOfAllPathwaysWeights(:,1)),:) = [];
                    end
                     
                     resultsStructure = struct('PATHWAY','', ...
                                            'PATHWAY_PROD','', ...
                                            'MODEL','', ...
                                            'STATISTICS', '', ...
                                            'STATISTICS_PROD', '', ...
                                            'POOL_METABOLITES', '', ...
                                            'POOL_METABOLITES_PROD', '', ...
                                            'ORGANISM_PATHWAYS', '', ...
                                            'ORGANISM_PATHWAYS_PROD', '', ...
                                            'WEIGHTS_OF_PATHWAY', '', ...
                                            'WEIGHTS_OF_PATHWAY_PROD', '', ...
                                            'NUMBER_OF_PATHWAY',0,...
                                            'NUMBER_OF_PATHWAY_PROD',0);

                      cPathway = {}; 
                      for il=1:length(currentPathway(:, 1))
                          if currentPathway(il) == 'C'
                              compoundStructure = get_compound_information(currentPathway(il,:));
                              cPathway{il} = [currentPathway(il,:) ' - ' compoundStructure.NAME];
                          else
                              reactionStructure = get_reaction_information(currentPathway(il,:));
                              cPathway{il} = [currentPathway(il,:) ' - ' reactionStructure.NAME];
                          end
                      end   
                      cPathwayProd = {}; 
                      for il=1:length(currentPathwayProd(:, 1))
                          if currentPathwayProd(il) == 'C'
                              compoundStructure = get_compound_information(currentPathwayProd(il,:));
                              cPathwayProd{il} = [currentPathwayProd(il,:) ' - ' compoundStructure.NAME];
                          else
                              reactionStructure = get_reaction_information(currentPathwayProd(il,:));
                              cPathwayProd{il} = [currentPathwayProd(il,:) ' - ' reactionStructure.NAME];
                          end
                      end    
                      resultsStructure.PATHWAY = equalise_lengths(cPathway);
                      resultsStructure.PATHWAY_PROD = equalise_lengths(cPathwayProd);
                      resultsStructure.MODEL = returnModel;
                      resultsStructure.STATISTICS = pathwayStatstics;
                      resultsStructure.STATISTICS_PROD = prod_pathwayStatstics;
                      
                      
                      if ~isempty(listOfPoolMetabolitesInPathway)
                          cPathway = {}; 
                          for ik=1:length(listOfPoolMetabolitesInPathway(:,1))
                              compoundStructure = get_compound_information(listOfPoolMetabolitesInPathway(ik,:));
                              cPathway{ik} = [listOfPoolMetabolitesInPathway(ik,:) ' - ' compoundStructure.NAME];
                          end    
                          resultsStructure.POOL_METABOLITES = equalise_lengths(cPathway); 
                      end
                      
                       if ~isempty(prod_listOfPoolMetabolitesInPathway)
                          cPathway = {}; 
                          for ik=1:length(prod_listOfPoolMetabolitesInPathway(:,1))
                              compoundStructure = get_compound_information(prod_listOfPoolMetabolitesInPathway(ik,:));
                              cPathway{ik} = [prod_listOfPoolMetabolitesInPathway(ik,:) ' - ' compoundStructure.NAME];
                          end    
                          resultsStructure.POOL_METABOLITES_PROD = equalise_lengths(cPathway); 
                       end

                      
                      if ~isempty(listOfPathwaysWhereReactionsArePresented)
                            resultsStructure.ORGANISM_PATHWAYS = equalise_lengths(listOfPathwaysWhereReactionsArePresented(:,1));
                      end
                       
                      if ~isempty(prod_listOfPathwaysWhereReactionsArePresented)
                        resultsStructure.ORGANISM_PATHWAYS_PROD = equalise_lengths(prod_listOfPathwaysWhereReactionsArePresented(:,1));
                      end

                      resultsStructure.WEIGHTS_OF_PATHWAY = arrayOfWeightsOfPathway;
                      resultsStructure.WEIGHTS_OF_PATHWAY_PROD = prod_weights;
                      resultsStructure.NUMBER_OF_PATHWAY = i; 
                      resultsStructure.NUMBER_OF_PATHWAY_PROD = ip; 
                      
                      analyzedPathways = [analyzedPathways; resultsStructure];

                      if ~index == 0
                          analyzedPathwaysTemporary = analyzedPathways;
                          for j = 1:length(analyzedPathwaysTemporary)
                             pathTemporary = analyzedPathwaysTemporary(j);
                             if isequal(pathTemporary.NUMBER_OF_PATHWAY_PROD, index) ...
                                     && isequal(pathTemporary.NUMBER_OF_PATHWAY, index_sub)
                                 analyzedPathways(j)=[];
                             end
                          end
                          clear analyzedPathwaysTemporary;
                      end
                else
                   message = 'Zero solution for FBA of product. Skipping this pathway!!!'
                end  
            

             end
             close(barP)
        else
           message = 'Zero solution for FBA of substrate. Skipping this pathway!!!'
        end   
    end
    close(bar)
    
    tElapsed = toc(tStart)
    
    assignin('base', 'arrayOfAllPathwaysWeights', arrayOfAllPathwaysWeights);
    assignin('base', 'analyzedPathways', analyzedPathways);
    assignin('base', 'tElapsedAnalyzis', tElapsed);
   
    clear arrayOfAllPathwaysWeights;
    clear analyzedPathways;
    clear listOfPathways;
    clear defines;
    clear model;
end

